package coco.component
{
	import coco.component.bar.BarTitle;
	import coco.core.coco;
	import coco.util.Utils;
	
	import flash.events.KeyboardEvent;
	
	import spark.components.Window;
	
	use namespace coco;
	
	public class CocoWindow extends Window
	{
		public function CocoWindow()
		{
			super();
			setFocus();
			addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
		}
		
		
		private function keyDown(e:KeyboardEvent):void
		{
			switch(e.charCode)
			{
				case 27:
					close();
			}
		}
		
		
		private var _cocoTitle:String = '';
		
		coco function get cocoTitle():String
		{
			return _cocoTitle;
		}
		
		coco function set cocoTitle(value:String):void
		{
			_cocoTitle = value;
			
			if(cocoC)
				cocoC.title = _cocoTitle;
			
			title = _cocoTitle;
		}
		
		
		override public function set resizable(value:Boolean):void
		{
			super.resizable = value;
		}
		
		/**
		 * coco
		 * */
		[SkinPart(required = 'true')]
		public var cocoC:BarTitle;
		
		
		override protected function partAdded(partName:String, instance:Object):void
		{
			if(instance == cocoC)
				cocoC.title = cocoTitle;
		}
		
		
		/**
		 * move to center of screen
		 * 
		 * @coco
		 * */
		coco function moveToCeneter():void
		{
			move(Utils.getCenterX() - width / 2, Utils.getCenterY() - height / 2);
		}
	}
}